class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode cur = new ListNode();
        ListNode head = cur;
        int t = 0;
        while (l1 != null && l2 != null) {
            t += l1.val + l2.val;
            ListNode node = new ListNode(t % 10);
            t /= 10;
            cur.next = node;
            cur = cur.next;
            l1 = l1.next;
            l2 = l2.next;
        }
        while (l1 != null) {
            t += l1.val;
            ListNode node = new ListNode(t % 10);
            t /= 10;
            cur.next = node;
            cur = cur.next;
            l1 = l1.next;
        }
        while (l2 != null) {
            t += l2.val;
            ListNode node = new ListNode(t % 10);
            t /= 10;
            cur.next = node;
            cur = cur.next;
            l2 = l2.next;
        }
        if (t != 0) {
            ListNode node = new ListNode(t);
            cur.next = node;
        }
        return head.next;
    }

}